package com.hspedu.springcloud.controller;

import com.hspedu.springcloud.entity.Member;
import com.hspedu.springcloud.entity.Result;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author Charlie
 * @version 1.0
 * @date 16/6/2025 下午11:08
 */
@RestController
@Slf4j
public class MemberConsumerController {

    @Resource
    private RestTemplate restTemplate;

    public static final String MEMBER_SERVICE_PROVIDER_URL=
            "http://localhost:10000";

    @PostMapping("/member/consumer/save")
    public Result<Member> save(Member member){
       log.info("service-consumer member={}",member);
       return restTemplate.postForObject(MEMBER_SERVICE_PROVIDER_URL+"/member/save",member,Result.class);
    }
    @GetMapping("/member/consumer/get/{id}")
    public Result<Member> getMemberById(@PathVariable("id") Long id){
        return restTemplate.getForObject(MEMBER_SERVICE_PROVIDER_URL+"/member/get/"+id,Result.class);

    }
}
